package com.dexilaonian.adpter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dexilaonian.R;
import com.dexilaonian.activity.StoreDetailActivity;

import java.util.List;

/**
 * Created by Administrator on 2018/6/14.
 */

public class StoreItemAdapter extends BaseAdapter{

    private final Context mContext;
    private final List<String> mStore_item_list;

    public StoreItemAdapter(Context context, List<String> store_item_key) {
        mContext = context;
        mStore_item_list = store_item_key;
    }

    @Override
    public int getCount() {
        return mStore_item_list == null ? 0 : mStore_item_list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.store_item, null);
            viewHolder.itemGuige = (TextView) convertView.findViewById(R.id.item_guige);
            convertView.setTag(viewHolder);
        }
        viewHolder = (ViewHolder) convertView.getTag();
        String s = mStore_item_list.get(position);
        viewHolder.itemGuige.setText(s);
        if (position == StoreDetailActivity.POSITION) {
            viewHolder.itemGuige.setBackgroundResource(R.drawable.guige);
        }else{
            viewHolder.itemGuige.setBackgroundResource(R.drawable.guigekuang);
        }
        return convertView;
    }
    class ViewHolder{
        TextView itemGuige;
    }
}
